<?php
class isp_lap_stock_barang_model extends MY_Model {
	var $model = 'isp_lap_stock_barang';
	
	function GetJSON()
	{
		$ls_sql	= "	SELECT	*
					FROM	ISP_INVENTORI
					WHERE	(UPPER(kode_inventori) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_inventori) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'kode_inventori' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
					
		return json_encode( $this->paging($ls_sql) );
	}
		
	function Add($arr_data){
		$this->db->insert('isp_inventori', $arr_data);
	}
	
	function Update($arr_data, $arr_rule){
		$this->db->update('isp_inventori', $arr_data, $arr_rule);
	}
	
	function GetSingle($as_kode_inventori){
		$result = $this->db->get_where('isp_inventori', array('kode_inventori' => $as_kode_inventori));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}
	
	function GetSingleView($as_kode_inventori)
	{
		$result = $this->db->get_where('isp_inventori', array('kode_inventori' => $as_kode_inventori));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}

	function DeleteSingle($arr_rule)
	{
		try {
			//if(	intval($this->get_data("SELECT COUNT(1) FROM isp_inventori WHERE kode_inventori = '".$arr_rule['kode_inventori']."'"))>0)
			//{
			//	return $this->error_delete.' [id: '.$arr_rule['kode_inventori']."]<br />";
			//}else{
				$this->db->delete('isp_inventori', array('kode_inventori' => $arr_rule['kode_inventori']));
				return '';
			//}
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}
}
?>